package com.loong.web.gp4j.service.message;

import java.util.List;

import org.springframework.web.util.HtmlUtils;

import com.loong.web.gp4j.bean.param.messages.MessageParam;
import com.loong.web.gp4j.bean.schema.message.MessageSchema;
import com.loong.web.gp4j.bean.vo.message.MessageVo;

/**
 * 消息封装器
 *
 * @author 张成轩
 */
public class MessageAdapter {

	/**
	 * @param schemas
	 * @param vos
	 */
	public static void convert(List<MessageSchema> schemas, List<MessageVo> vos) {

		for (MessageSchema schema : schemas) {

			MessageVo vo = new MessageVo();
			vos.add(vo);

			convert(schema, vo);
		}
	}

	/**
	 * @param schema
	 * @param vo
	 */
	public static void convert(MessageSchema schema, MessageVo vo) {

		vo.setId(schema.getId());
		vo.setTitle(schema.getTitle());
		vo.setContent(HtmlUtils.htmlEscape(schema.getContent()));
		vo.setTime(schema.getTime());
		if (schema.getUser() != null)
			vo.setCreater(schema.getUser().getUser());
	}

	/**
	 * @param param
	 * @param schema
	 */
	public static void convert(MessageParam param, MessageSchema schema) {

		schema.setContent(param.getContent());
		schema.setTitle(param.getTitle());
	}
}
